
cc.Class({
  extends: cc.Component,

  properties: {
    baseScoreTitle: {
      default: null,
      type: cc.Label
    },
    myPrefab: {
      default: null,
      type: cc.Prefab
    },
    forePrefab: {
      default: null,
      type: cc.Prefab
    },
    backPrefab: {
      default: null,
      type: cc.Prefab
    },
    myHeadIcon: {
      default: null,
      type: cc.Sprite
    },
    myScore: {
      default: null,
      type: cc.Label
    },
    myName: {
      default: null,
      type: cc.Label
    },
    myRank: {
      default: null,
      type: cc.Label
    },
    foreHeadIcon: {
      default: null,
      type: cc.Sprite
    },
    foreScore: {
      default: null,
      type: cc.Label
    },
    foreName: {
      default: null,
      type: cc.Label
    },
    foreRank: {
      default: null,
      type: cc.Label
    },
    backHeadIcon: {
      default: null,
      type: cc.Sprite
    },
    backScore: {
      default: null,
      type: cc.Label
    },
    backName: {
      default: null,
      type: cc.Label
    },
    backRank: {
      default: null,
      type: cc.Label
    },
    maxScorePlayer: {
      default: null,
      type: cc.Label
    },
  },

  onLoad: function () {
    this.baseScoreTitle.string = "0";
    this.maxScorePlayer.string = "我的历史最高分:999";

    this.foreName.string = "";
    this.foreScore.string = "";
    this.foreRank.string = "没有玩家";
    this.backName.string = "";
    this.backScore.string = "";
    this.backRank.string = "没有玩家";
    this.myName.string = "";
    this.myScore.string = "";
    this.myRank.string = "没有玩家";
    // this.currentScore = 0;
  },

  update: function (dt) {
  },

  updateBaseScore: function (targetScore, scoreReplys) {
    this.baseScoreTitle.string = targetScore;
    // this.MyScore.string = targetScore;
    // this.MyName.string = name;
    if (scoreReplys == null){
      return;
    }
    var self = this;
    var oneInfo = scoreReplys[0]
    var twoInfo = scoreReplys[1]
    var threeInfo = scoreReplys[2]
    if (oneInfo != null && oneInfo.isMe) {
      var foreInfo = null
      var myInfo = oneInfo
      var backInfo = twoInfo
    }
    if (twoInfo != null && twoInfo.isMe) {
      var foreInfo = oneInfo
      var myInfo = twoInfo
      var backInfo = threeInfo
    }
    if (threeInfo != null && threeInfo.isMe) {
      var foreInfo = twoInfo
      var myInfo = threeInfo
      var backInfo = null
    }
    if (myInfo != null) {
      this.maxScorePlayer.string = "我的历史最高分:" + myInfo.score;
      this.myName.string = myInfo.nickName;
      this.myScore.string = myInfo.score;
      this.myRank.string = myInfo.rank;
      if (myInfo.avatarURL != null && myInfo.avatarURL != "") {
        cc.loader.load({ url: myInfo.avatarURL, type: 'jpg' }, function (err, texture) {
          // Use texture to create sprite frame
          if (err) {
            // cc.tool.msgBox.addMsg(err)
            console.error("头像err : " + err)
          } else {
            var s = new cc.SpriteFrame(texture);
            self.myHeadIcon.spriteFrame = s;
          }
        });
      }
    }
    if (foreInfo != null) {
      this.foreName.string = foreInfo.nickName;
      this.foreScore.string = foreInfo.score;
      this.foreRank.string = foreInfo.rank;
      if (foreInfo.avatarURL != null && foreInfo.avatarURL != "") {
        cc.loader.load({ url: foreInfo.avatarURL, type: 'jpg' }, function (err, texture) {
          // Use texture to create sprite frame
          if (err) {
            // cc.tool.msgBox.addMsg(err)
            console.error("头像err : " + err)
          } else {
            var s = new cc.SpriteFrame(texture);
            self.foreHeadIcon.spriteFrame = s;
          }
        });
      }
    }
    if (backInfo != null) {
      this.backName.string = backInfo.nickName;
      this.backScore.string = backInfo.score;
      this.backRank.string = backInfo.rank;
      if (backInfo.avatarURL != null && backInfo.avatarURL != "") {
        cc.loader.load({ url: backInfo.avatarURL, type: 'jpg' }, function (err, texture) {
          // Use texture to create sprite frame
          if (err) {
            // cc.tool.msgBox.addMsg(err)
            console.error("头像err : " + err)
          } else {
            var s = new cc.SpriteFrame(texture);
            self.backHeadIcon.spriteFrame = s;
          }
        });
      }
    }
  }

});
